<%@ page language="java" import="java.util.*,com.beans.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title></title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	
	<link rel="stylesheet" type="text/css" href="css/maintable.css" ></link>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/maintable.css">
	
	<script type="text/javascript" src="js/jquery-1.8.0.js"></script> 
	<script type="text/javascript">
		$(function(){
			$("#ch_checkall,#top_ch_checkall").click(function(){
				if(this.checked){
					$("input[name=ck_id]").attr("checked","checked");
				}else{
					$("input[name=ck_id]").removeAttr("checked");
				}		
			});
					
			$("table tr").mouseover(function(){
				$(this).css("background","#D3EAEF");
				$(this).siblings().css("background","white");
			});
		});
		
		//分页的“转到”功能
		function subForm(pageIndex){
			document.form1.action="AdminServlet.do?flag=manage&pageIndex="+pageIndex;
			document.form1.submit();
		}
		
		//删除用户，将状态设为0，在列表里不显示
		//用ajax验证删除的是不是自己，不是才能发送请求
		//ajax验证可以保证不回发，不刷新当前页
		function del(id){
			if(confirm('确定要删除吗')){
				var currentAdminId=${session_admin.id};  //取到Session中的 admin 的 id
				if(currentAdminId==''){
					alert("当前用户的session已失效!请重新登录");
					window.top.location.href = "${pageContext.request.contextPath}/login.jsp";
				}
				else{
					if(currentAdminId==id){
						alert("不能删除自已!");
					}
					else{
						window.location.href="${pageContext.request.contextPath}/AdminServlet.do?flag=del&id="+id;
					}
				}
			}
		}
		
		//给某个账号进行锁定或解锁
		//lockFlag 为lock表示锁定，为unlock表示解锁
		function lock(id,item,pageIndex){
            var msg;
            var lockFlag;
            if(item==true){
            	lockFlag = "lock";
                msg="确定要锁定吗";
            }
            if(item==false){
            	lockFlag = "unlock";
                msg="确定要解锁吗";
            }
            if(confirm(msg)){
            	window.location.href="${pageContext.request.contextPath}/AdminServlet.do?flag="+lockFlag+"&id="+id+"&pageIndex="+pageIndex;
            }else{
                return false;
            }
        }
		
		//删除多个用户
		function delMore(){
			
		}
		
	</script>

	<style type="text/css">
		.desc{
			width:200px;
            word-break:break-all;
            display:-webkit-box;
            -webkit-line-clamp:1;
            -webkit-box-orient:vertical;
            overflow:hidden;
		}
	</style>

  </head>
  
  <body>
	 <div class ="div_title">
		<div class="div_titlename"> <img src="images/san_jiao.gif" ><span>管理人员基本信息列表</span></div>
		<div class="div_titleoper">
		<input type="checkbox" id="top_ch_checkall"/> 全选 <a href="admin/admin_add.jsp"> <img src="images/add.gif"/>添加 </a> <a href="AdminServlet.do?flag=delMore"><img src="images/del.gif"/>删除</a> </div>
	 </div>
	 
	 <form action="AdminServlet"  name="form1" method="post">
		 <table class="main_table">
		     <tr>
	 				<th><input type="checkbox" id="ch_checkall" /></th>
	 			    <th>账号</th> 	
	 			    <th>状态</th>	
	 			    <th>备注</th>  
	 			    <th>最后更新日期</th> 	
	 			    <th>操作</th>
	 		</tr>
 		
	 		<c:forEach var="admin" items="${adminList }">
	 			<tr>
	 				<td>
	 					<input type="checkbox" name="ck_id" value="${admin.id }" /> 
	 				</td>
	 				<td>${admin.adminName }</td>	
	 				<td>
						<c:choose>
							<c:when test="${admin.state==1 }"></c:when>
							<c:when test="${admin.state==2 }">已锁定</c:when>
						</c:choose>
					</td>	
	 				<td> 
	 					<div class="desc">
	 						<a title="${admin.note }">${admin.note }</a> 
	 					</div>
	 				</td>	
	 				<td>
	 					${admin.editDate}
	 					<!-- <fmt:formatDate value=""   pattern="yyyy-MM-dd  hh:mm" />	-->
	 				</td>	
	 				<td>
						<c:if test="${admin.state=='2'}">
		 					<a href="javascript:lock(${admin.id},false,${page.pageIndex })">解锁</a> | 
		 				</c:if>
		 				<c:if test="${admin.state=='1'}">
		 					<a href="javascript:lock(${admin.id},true,${page.pageIndex })">锁定</a> |  
		 				</c:if>
		 				<c:if test="${admin.state=='1'}">
		 					<a href="${pageContext.request.contextPath }/AdminServlet.do?flag=searchforupdate&id=${admin.id}">修改</a> |  
		 				</c:if>
		 							
		 			    <a href="javascript:del(${admin.id })">删除</a> 
	 				</td>
	 			</tr>
	 		</c:forEach>
	 		
		</table>
	</form>
	
	<div class="div_page" >
		  <div class="div_page_left">    共
		  	有 <label>${page.rowCount }</label> 条记录，当前第 <label>${page.pageIndex }</label> 页，共 <label>${page.pageCount }</label> 页	</div>		
		  <div class="div_page_right" > 	 
		  	<c:choose>
		  		<c:when test="${page.hasPre }">
		  			<a href="AdminServlet.do?flag=manage&pageIndex=1">首页</a>
		  			<a href="AdminServlet.do?flag=manage&pageIndex=${page.pageIndex-1 }">上一页</a>  &nbsp;  &nbsp;  &nbsp;  &nbsp;
		  		</c:when>
		  		<c:otherwise>
		  			 首页
	  	 			 上一页
		  		</c:otherwise>
		  	</c:choose>
		  	
		  	<c:choose>
		  		<c:when test="${page.hasNext }">
		  			<a href="AdminServlet.do?flag=manage&pageIndex=${page.pageIndex+1 }">下一页</a>
		  			<a href="AdminServlet.do?flag=manage&pageIndex=${page.pageCount }">尾页</a>  &nbsp;  &nbsp;  &nbsp;  &nbsp;
		  		</c:when>
		  		<c:otherwise>
		  			 下一页 
	  	 		   	尾页
		  		</c:otherwise>
		  	</c:choose>

	  	  <button onclick="javascript:subForm(${page.pageIndex+1})">转到</button>
	  	  <input type="text" name="pageIndex" id="pageIndex" value="${page.pageIndex }" /> 页
	  </div>	
	</div>
  </body>
</html>
